from PySide6.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton

class IPInputDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("连接视频服务器")
        self.setup_ui()
        
    def setup_ui(self):
        layout = QVBoxLayout(self)
        
        # IP地址输入框
        ip_layout = QHBoxLayout()
        ip_label = QLabel("IP地址:")
        self.ip_input = QLineEdit()
        self.ip_input.setPlaceholderText("例如: 192.168.0.92")
        ip_layout.addWidget(ip_label)
        ip_layout.addWidget(self.ip_input)
        layout.addLayout(ip_layout)
        
        # 端口输入框
        port_layout = QHBoxLayout()
        port_label = QLabel("端口:")
        self.port_input = QLineEdit()
        self.port_input.setPlaceholderText("例如: 5000")
        self.port_input.setText("5000")  # 默认端口
        port_layout.addWidget(port_label)
        port_layout.addWidget(self.port_input)
        layout.addLayout(port_layout)
        
        # 按钮布局
        button_layout = QHBoxLayout()
        self.connect_button = QPushButton("连接")
        self.cancel_button = QPushButton("取消")
        button_layout.addWidget(self.connect_button)
        button_layout.addWidget(self.cancel_button)
        layout.addLayout(button_layout)
        
        # 连接信号
        self.connect_button.clicked.connect(self.accept)
        self.cancel_button.clicked.connect(self.reject)
        
    def get_ip_address(self):
        return self.ip_input.text()
        
    def get_port(self):
        return self.port_input.text()
